package cn.fl.carloan.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.api.ISysRegionApiService;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysOrgApiService;
import cmm.user.facade.system.api.ISysUsrApiService;
import cmm.user.facade.system.api.ISysUsrQueryApiService;
import cmm.user.facade.system.condition.SysUsrFunAuthRQueryCondition;
import cmm.user.facade.system.condition.SysUsrQueryCondition;
import cmm.user.facade.system.constant.SysUsrSysRConstant;
import cmm.user.facade.system.dto.SysRefUsrDTO;
import cmm.user.facade.system.dto.SysUsrDTO;
import cmm.user.facade.system.dto.SysUsrFunAuthRDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.*;
import cn.fl.carloan.service.IOdrBscInfoService;
import cn.fl.carloan.service.IOdrClueInfoService;
import cn.fl.carloan.service.IOdrClueRemService;
import cn.fl.carloan.transform.OdrCarValRecordVOTransform;
import cn.fl.carloan.vo.OdrCarValRecordVO;
import cn.fl.carloan.vo.OdrClueInfoVO;
import cn.fl.carloan.vo.OdrClueRemVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.ref.fncprjbscinfo.util.DateUtil;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSONObject;

import fl.carloan.facade.carloan.api.IOdrCarValRecordApiService;
import fl.carloan.facade.carloan.api.IOdrEplyInfoApiService;
import fl.carloan.facade.carloan.api.IOdrUsrDingApiService;
import fl.carloan.facade.carloan.condition.OdrCarValRecordQC;
import fl.carloan.facade.carloan.condition.OdrClueInfoQC;
import fl.carloan.facade.carloan.condition.OdrUsrDingQC;
import fl.carloan.facade.carloan.constant.OdrBscInfoConstant;
import fl.carloan.facade.carloan.constant.OdrCommonConstant;
import fl.carloan.facade.carloan.dto.OdrCarValRecordDTO;
import fl.carloan.facade.carloan.dto.OdrClueInfoDTO;
import fl.carloan.facade.carloan.dto.OdrUsrDingDTO;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Description: 线索线索表 控制层
 */
@Controller
@RequestMapping("/carloan/odrclueinfo")
public class OdrClueInfoController extends BaseController {


    private static final Logger logger = LoggerFactory.getLogger(OdrClueInfoController.class);

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * OdrClueInfo 服务层BEAN
     */
    @Autowired
    private IOdrClueInfoService odrClueInfoService;

    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

    @Autowired
    private IOdrBscInfoService odrBscInfoService;

    @Autowired
    ISysUsrQueryApiService sysUsrQueryApiService;

    @Autowired
    ISysUsrApiService sysUsrApiService;

    @Autowired
    private IOdrClueRemService odrClueRemService;

    @Autowired
    private IOdrEplyInfoApiService odrEplyInfoApiService;
    @Autowired
    private ISysRegionApiService sysRegionApiService;

    @Autowired
    private IOdrUsrDingApiService odrUsrDingApiService;


    @Autowired
    private IOdrCarValRecordApiService odrCarValRecordApiService;

    @Autowired
    private ISysOrgApiService sysOrgApiService;

    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toListPage", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        ModelAndView view = new ModelAndView("carloan/odrclueinfo/odrClueInfoList");
        // 事业部
        List<KeyValueVO> orgList = this.odrBscInfoService.searchBusinessOrgList();
//        List<KeyValueVO> odrStsCdList = this.odrBscInfoService.getOdrStsCdList();
        List<KeyValueVO> odrClueStsCdList = this.odrClueInfoService.searchCdList(OdrBscInfoConstant.ODR_CLUE_STS_CD);
        view.addObject("orgList", orgList);
        view.addObject("odrStsCdList", odrClueStsCdList);
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toListPage", "加载列表页面.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        return view;
    }

    /**
     * 到修改页面
     */
    @RequestMapping(value = "/toModifyPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
        String id = request.getParameter("id");
        ModelAndView view = new ModelAndView("service/odrClueInfo/modify");
        view.addObject("id", id);
        BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id=" + id + "]", CurrentThreadContext.getCurrentUserName());
        return view;
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initList(HttpServletRequest request, HttpServletResponse response) throws ParseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initList", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String odrNo = request.getParameter("odrNo");//线索编号
        String cstNm = request.getParameter("cstNm");//客户名称
        String cstMgrNm = request.getParameter("cstMgrNm");//客户经理
        String odrStsCd = request.getParameter("odrStsCd");//线索状态
        String firstUsrNm = request.getParameter("firstUsrNm");//一级推荐人id
        String secondUsrNm = request.getParameter("secondUsrNm");//二级推荐人id
        String buOrgCd = request.getParameter("buOrgCd");//所属事业部
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        OdrClueInfoQC qc = new OdrClueInfoQC();
        if (StringUtils.isNotEmpty(odrNo)) {
            qc.setClueNo(odrNo);
        }
        if (StringUtils.isNotEmpty(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotEmpty(cstMgrNm)) {
            qc.setCstMgrNm(cstMgrNm);
        }
        if (StringUtils.isNotEmpty(odrStsCd)) {
            qc.setClueStsCd(odrStsCd);
        }
        if (StringUtils.isNotEmpty(firstUsrNm)) {
            qc.setFirstUsrNm(firstUsrNm);
        }
        if (StringUtils.isNotEmpty(secondUsrNm)) {
            qc.setSecondUsrNm(secondUsrNm);
        }

        if (StringUtils.isNotEmpty(buOrgCd)) {
            qc.setBuOrgCd(buOrgCd);
        }
        if (StringUtils.isNotEmpty(beginTime)) {
            Date dateByStringTime = DateUtil.getDateByStringTime(beginTime);
            // Date dateAddDate = DateUtils.getDateAddDate(dateByStringTime, 5, -1);
            String format = sdf.format(dateByStringTime);
            Date parse = sdf.parse(format);
            qc.setBeginTime(parse);
        }
        if (StringUtils.isNotEmpty(endTime)) {
            Date dateByStringTime = DateUtil.getDateByStringTime(endTime);
            //  Date dateAddDate = DateUtils.getDateAddDate(dateByStringTime, 5, -1);
            String format = sdf.format(dateByStringTime);
            Date parse = sdf.parse(format);
            qc.setEndTime(parse);
        }

        //数据权限
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        qc.setDataUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
        page.setCondition(qc);
        Pager pager = this.odrClueInfoService.searchListPage(page);
        List<OdrClueInfoVO> list = (List<OdrClueInfoVO>) pager.getResultList();
        for (OdrClueInfoVO odrClueInfoVO : list) {
            odrClueInfoVO.setClueId(odrClueInfoVO.getId() + "");
            if (StringUtils.isNotEmpty(odrClueInfoVO.getRcdId()) && "BX_01".equals(odrClueInfoVO.getResCd())) {
                SysUsrDTO usrDTO = sysUsrApiService.selectSysUsrById(odrClueInfoVO.getRcdId(), "11000", "0000");
                if (null != usrDTO) {
                    odrClueInfoVO.setCstMgrMp(usrDTO.getMp());
                    String mp = usrDTO.getMp();
                    SysUsrQueryCondition condition = new SysUsrQueryCondition();
                    condition.setMp(mp);
                    condition.setSysCd("11000");
                    List<SysUsrDTO> sysUsrDTOS = sysUsrApiService.selectUserList(condition);
                    if (CollectionUtils.isNotEmpty(sysUsrDTOS)) {
                        for (SysUsrDTO sysUsrDTO : sysUsrDTOS) {
                            if (!odrClueInfoVO.getRcdId().equals(sysUsrDTO.getId())) {
                                odrClueInfoVO.setRcdId(sysUsrDTO.getId());
                            }
                        }
                    }
                }

                OdrUsrDingQC condition = new OdrUsrDingQC();
                condition.setUsrId(odrClueInfoVO.getRcdId());
                List<OdrUsrDingDTO> odrUsrDingDTOS = odrUsrDingApiService.selectDingIdByUsrId(condition);
                if (CollectionUtils.isNotEmpty(odrUsrDingDTOS)) {
                    odrClueInfoVO.setCstMgrNm(odrUsrDingDTOS.get(0).getDdUsrNm());
                }
                SysUsrFunAuthRQueryCondition usrFunAuthRQueryCondition = new SysUsrFunAuthRQueryCondition();
                List ids = new ArrayList(1);
                ids.add(odrClueInfoVO.getRcdId());
                usrFunAuthRQueryCondition.setUsrIdList(ids);
                usrFunAuthRQueryCondition.setSysCd("11000");
                List<SysUsrFunAuthRDTO> sysUsrFunAuthRDTOS = sysUsrApiService.selectOrgCdByUsrIds(usrFunAuthRQueryCondition);
                if (CollectionUtils.isNotEmpty(sysUsrFunAuthRDTOS)) {
                    for (SysUsrFunAuthRDTO sysUsrFunAuthRDTO : sysUsrFunAuthRDTOS) {
                        if (sysUsrFunAuthRDTO.getOrgCd().length() >= 16) {
                            String orgCd = sysUsrFunAuthRDTO.getOrgCd();
                            if (orgCd.length() == 16) {
                                String prnNm = sysOrgApiService.selectSysOrgNmByOrgCd(orgCd, "11000");
                                odrClueInfoVO.setRgnPrCd(prnNm);
                            } else {
                                String prnNm = sysOrgApiService.selectSysOrgNmByOrgCd(orgCd.substring(0, 16), "11000");
                                odrClueInfoVO.setRgnPrCd(prnNm);
                                String cyNm = sysOrgApiService.selectSysOrgNmByOrgCd(orgCd, "11000");
                                odrClueInfoVO.setRgnCyCd(cyNm);
                            }
                        }
                    }
                }
            }
            Long contAmt = odrClueInfoVO.getContAmt();
            if (contAmt != null) {
                odrClueInfoVO.setContAmtD(DecimalUtils.div(DecimalUtils.convertFenToYuan(contAmt), 10000, 2));
            }
        }

        ListPageVO<OdrClueInfoVO> listPage = new ListPageVO<OdrClueInfoVO>(list, pager.getTotalCount());

        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initList", "加载列表页面.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        return listPage;
    }

    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeById.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            return result;
        }
        try {
            this.odrClueInfoService.removeById(Long.valueOf(id));
            BaseLogUtils.info(logger, "removeById", "删除数据.[id=" + id + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "removeById", "删除数据失败.[id=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removeById", "删除数据失败.[id=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }

        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getById.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id=" + id + "]", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            OdrClueInfoVO vo = this.odrClueInfoService.selectById(Long.valueOf(id));

            //推荐人信息
            List<Long> refUsrList = new ArrayList<Long>();
            refUsrList.add(vo.getUsrId());
            List<SysRefUsrDTO> sysRefUsrDTOs = this.sysUsrQueryApiService.searchRefUsrInfoListUp(refUsrList, OdrBscInfoConstant.SYS_CD, SysUsrSysRConstant.REF_USR_BUS_TYP_1);
            List<Long> refUsrOneIds = new ArrayList<>();
            List<Long> refUsrTwoIds = new ArrayList<>();
            List<Long> usrIds = new ArrayList<>();
            for (SysRefUsrDTO sysRefUsrDTO : sysRefUsrDTOs) {
                if (null != sysRefUsrDTO.getRefUsrOneId()) {
                    Long refUsrOneId = sysRefUsrDTO.getRefUsrOneId();
                    refUsrOneIds.add(refUsrOneId);
                }
                if (null != sysRefUsrDTO.getRefUsrTwoId()) {
                    Long refUsrTwoId = sysRefUsrDTO.getRefUsrTwoId();
                    refUsrTwoIds.add(refUsrTwoId);
                }
            }
            usrIds.addAll(refUsrOneIds);
            usrIds.addAll(refUsrTwoIds);
            if (CollectionUtils.isNotEmpty(usrIds) || usrIds.size() > 0) {
                List<SysUsrDTO> sysUsrDTOS = sysUsrApiService.selectSysUsrList(usrIds);
                for (SysUsrDTO sysUsrDTO : sysUsrDTOS) {
                    Long userId = sysUsrDTO.getId();
                    if (refUsrOneIds.contains(userId)) {
                        vo.setOneMp(sysUsrDTO.getMp());
                    }
                    if (refUsrTwoIds.contains(userId)) {
                        vo.setTwoMp(sysUsrDTO.getMp());
                    }
                }
            }
            if (null == vo) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id=" + id + "]", CurrentThreadContext.getCurrentUserName());
            }
            result.setData(vo);
            BaseLogUtils.info(logger, "getById", "获取数据.[id=" + id + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "getById", "获取失败.[id=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getById", "获取失败.[id=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "add", "新增对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        String name = request.getParameter("name");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
        OdrClueInfoVO entity = null;
        try {
            entity = new OdrClueInfoVO();
            //TODO ADD PARAM
            Long id = this.odrClueInfoService.add(entity);
            result.setData(id);
            BaseLogUtils.info(logger, "add", "新增数据.[id=" + id + "] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "add", "新增对象失败,name[" + name + "].", CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.error(logger, "add", "新增对象失败,name[" + name + "].", CurrentThreadContext.getCurrentUserName(), ex);
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "add", "新增对象.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());

        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modify.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id=" + id + "]", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        OdrClueInfoVO entity = null;
        try {
            entity = new OdrClueInfoVO();
            entity.setId(Long.valueOf(id));
            //entity.setName(name);
            //TODO ADD PARAM
            boolean success = this.odrClueInfoService.modify(entity);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
                BaseLogUtils.info(logger, "modify", "修改失败.[id=" + id + "] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            }
            BaseLogUtils.info(logger, "modify", "修改成功.[id=" + id + "] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modify", "修改失败.[id=" + id + "] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modify", "修改失败.[id=" + id + "] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 立即申请-新增线索信息
     */
    @RequestMapping(value = "/addClueInfo.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addClueInfo(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addClueInfo", "新增对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
        //线索表属性
        String usrId = request.getParameter("usrId");//用户Id
        String cstId = request.getParameter("cstId");//客户Id(非必须)
        String dateResCd = request.getParameter("dateResCd");//数据来源
        String contAmt = request.getParameter("contAmt");//贷款金额
        String rgnPrCd = request.getParameter("rgnPrCd");//所属省
        String rgnCyCd = request.getParameter("rgnCyCd");//所属市
        String licDt = request.getParameter("licDt");//上牌时间
        String invoiceAmt = request.getParameter("invoiceAmt");//购车发票金额
        String PrdAmt = request.getParameter("PrdAmt");//评估价值
        String resCd = request.getParameter("resCd");

        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
        if (StringUtils.isEmpty(dateResCd)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("数据来源不能为空!");
            BaseLogUtils.info(logger, "addClueInfo", "数据来源不能为空", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        if (StringUtils.isEmpty(usrId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("用户ID不能为空!");
            BaseLogUtils.info(logger, "addClueInfo", "用户ID不能为空", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        if (StringUtils.isEmpty(contAmt)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("贷款金额不能为空!");
            BaseLogUtils.info(logger, "addClueInfo", "贷款金额不能为空", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        if (StringUtils.isEmpty(invoiceAmt)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("购车发票金额不能为空!");
            BaseLogUtils.info(logger, "addClueInfo", "购车发票金额不能为空", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        if (StringUtils.isEmpty(licDt)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("上牌时间不能为空!");
            BaseLogUtils.info(logger, "addClueInfo", "上牌时间不能为空", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        if (StringUtils.isEmpty(PrdAmt)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("评估价值不能为空!");
            BaseLogUtils.info(logger, "addClueInfo", "评估价值不能为空", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        //线索VO对象
        OdrClueInfoVO odrClueInfoVO = new OdrClueInfoVO();

        try {

            if (StringUtils.isNotEmpty(cstId)) {
                odrClueInfoVO.setCstId(Long.valueOf(cstId));
            }

            odrClueInfoVO.setUsrId(Long.valueOf(usrId));
            odrClueInfoVO.setDateResCd(dateResCd);


            Long contAmtL = DecimalUtils.convertYuanToFen(Double.valueOf(contAmt));
            odrClueInfoVO.setContAmt(contAmtL);


            odrClueInfoVO.setRgnPrCd(rgnPrCd);
            odrClueInfoVO.setRgnCyCd(rgnCyCd);
            odrClueInfoVO.setLicDt(DateUtils.formatStringToDate(licDt, DateUtils.YYYY_MM_DD));

            if (StringUtils.isNotEmpty(invoiceAmt)) {
                Long invoiceAmtL = DecimalUtils.convertYuanToFen(Double.valueOf(invoiceAmt));
                odrClueInfoVO.setInvoiceAmt(invoiceAmtL);
            }
            Long PrdAmtL = DecimalUtils.convertYuanToFen(Double.valueOf(PrdAmt));
            odrClueInfoVO.setPrdAmt(PrdAmtL);
            if (StringUtils.isNotEmpty(resCd)) {
                odrClueInfoVO.setResCd(resCd);
            }

            Long id = this.odrClueInfoService.addClueInfo(odrClueInfoVO);
            result.setData(id);
            BaseLogUtils.info(logger, "addClueInfo", "新增数据.[id=" + id + "] ", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "addClueInfo", "新增对象失败", CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.error(logger, "addClueInfo", "新增对象失败", CurrentThreadContext.getCurrentUserName(), ex);
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addClueInfo", "新增对象.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());

        return result;
    }


    /**
     * 获取我的线索记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/searchClueList.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object searchClueList(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "searchClueList", "获取我的线索记录：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        String usrId = request.getParameter("usrId");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");

        if (StringUtils.isEmpty(usrId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("缺少用户ID");
            BaseLogUtils.info(logger, "addCredit", "缺少用户ID", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {

            OdrClueInfoQC odrClueInfoQC = new OdrClueInfoQC();
            odrClueInfoQC.setUsrId(Long.valueOf(usrId));
            List<OdrClueInfoDTO> odrBscInfoResultDTOS = this.odrClueInfoService.searchClueList(odrClueInfoQC);
            result.setData(odrBscInfoResultDTOS);
            BaseLogUtils.info(logger, "searchClueList", "获取我的线索记录", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "searchClueList", "获取我的线索记录", CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.error(logger, "searchClueList", "获取我的线索记录", CurrentThreadContext.getCurrentUserName(), ex);
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "searchClueList", "获取我的线索记录：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 线索信息绑定客户
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/setCstToOdrClue.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object setCstToOdrClue(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "setCstToOdrClue", "线索信息绑定客户：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        String cstId = request.getParameter("cstId");
        String usrId = request.getParameter("usrId");
        String odrId = request.getParameter("odrId");//线索Id

        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
        if (StringUtils.isEmpty(cstId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("缺少客户ID");
            BaseLogUtils.info(logger, "setCstToOdrClue", "缺少客户ID", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        if (StringUtils.isEmpty(odrId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("缺少线索ID");
            BaseLogUtils.info(logger, "setCstToOdrClue", "缺少线索ID", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        if (StringUtils.isEmpty(usrId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("缺少用户ID");
            BaseLogUtils.info(logger, "setCstToOdrClue", "缺少用户ID", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        OdrClueInfoVO odrClueInfoVO = null;
        try {
            odrClueInfoVO = new OdrClueInfoVO();
            odrClueInfoVO.setCstId(Long.valueOf(cstId));
            odrClueInfoVO.setUsrId(Long.valueOf(usrId));
            odrClueInfoVO.setId(Long.valueOf(odrId));
            boolean b = this.odrClueInfoService.setCstToOdrClue(odrClueInfoVO);
            BaseLogUtils.info(logger, "setCstToOdrClue", "线索信息绑定客户", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "setCstToOdrClue", "线索信息绑定客户", CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.error(logger, "setCstToOdrClue", "线索信息绑定客户", CurrentThreadContext.getCurrentUserName(), ex);
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "setCstToOdrClue", "线索信息绑定客户：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 到详情页面
     */
    @RequestMapping(value = "/toDetailPage.do", method = {RequestMethod.GET})
    public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toDetailPage", "加载例子详细页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        String id = request.getParameter("id");
        ModelAndView view = new ModelAndView("carloan/odrclueinfo/odrClueInfoDetail");
        view.addObject("id", id);
        OdrClueInfoVO vo = this.odrClueInfoService.selectById(Long.valueOf(id));

        vo.setContAmtD(DecimalUtils.div(DecimalUtils.convertFenToYuan(vo.getContAmt()), 10000, 2));
        //推荐人信息
        List<Long> refUsrList = new ArrayList<Long>();
        refUsrList.add(vo.getUsrId());
        List<SysRefUsrDTO> sysRefUsrDTOs = this.sysUsrQueryApiService.searchRefUsrInfoListUp(refUsrList, OdrBscInfoConstant.SYS_CD, SysUsrSysRConstant.REF_USR_BUS_TYP_1);
        List<Long> refUsrOneIds = new ArrayList<>();
        List<Long> refUsrTwoIds = new ArrayList<>();
        List<Long> usrIds = new ArrayList<>();
        for (SysRefUsrDTO sysRefUsrDTO : sysRefUsrDTOs) {
            if (null != sysRefUsrDTO.getRefUsrOneId()) {
                Long refUsrOneId = sysRefUsrDTO.getRefUsrOneId();
                refUsrOneIds.add(refUsrOneId);
            }
            if (null != sysRefUsrDTO.getRefUsrTwoId()) {
                Long refUsrTwoId = sysRefUsrDTO.getRefUsrTwoId();
                refUsrTwoIds.add(refUsrTwoId);
            }
        }
        usrIds.addAll(refUsrOneIds);
        usrIds.addAll(refUsrTwoIds);
        if (CollectionUtils.isNotEmpty(usrIds) || usrIds.size() > 0) {
            List<SysUsrDTO> sysUsrDTOS = sysUsrApiService.selectSysUsrList(usrIds);
            for (SysUsrDTO sysUsrDTO : sysUsrDTOS) {
                Long userId = sysUsrDTO.getId();
                if (refUsrOneIds.contains(userId)) {
                    vo.setOneMp(sysUsrDTO.getMp());

                }
                if (refUsrTwoIds.contains(userId)) {
                    vo.setTwoMp(sysUsrDTO.getMp());
                }
            }
        }
        if (StringUtils.isEmpty(vo.getOneMp()) && StringUtils.isNotEmpty(vo.getRcdId()) && "BX_01".equals(vo.getResCd())) {
            SysUsrDTO usrDTO = sysUsrApiService.selectSysUsrById(vo.getRcdId(), "11000", "0000");
            if (null != usrDTO) {
                vo.setOneMp(usrDTO.getMp());
            }
        }
        Map<String, String> clueStsMap = this.sysDictionaryApiService.searchGroupToMap(OdrCommonConstant.SYS_CD, OdrCommonConstant.ORG_CD, OdrCommonConstant.CODE_GRP_CD_CLUE);
        vo.setClueStsCdNm(clueStsMap.get(vo.getClueStsCd()));
        List<OdrClueRemVO> remList = odrClueRemService.selectRemListByClueId(id);
        view.addObject("odrClueInfoVO", vo);
        view.addObject("remList", remList);

        //查询线索用户估值记录
        OdrCarValRecordQC odrCarValRecordQC = new OdrCarValRecordQC();
        odrCarValRecordQC.setClueId(vo.getId());
        List<OdrCarValRecordDTO> odrCarValRecordDTOList = this.odrCarValRecordApiService.searchByQc(odrCarValRecordQC);
        List<OdrCarValRecordVO> odrCarValRecordVoList = OdrCarValRecordVOTransform.toVOList(odrCarValRecordDTOList);
        view.addObject("odrCarValRecordVoList", odrCarValRecordVoList);
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toDetailPage", " 加载例子详细页面.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        return view;
    }


    // toUpdateDetailPage

    /**
     * 到修改详情页面
     */
    @RequestMapping(value = "/toUpdateDetailPage.do", method = {RequestMethod.GET})
    public ModelAndView toUpdateDetailPage(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toDetailPage", "加载例子详细页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        String id = request.getParameter("id");
        ModelAndView view = new ModelAndView("carloan/odrclueinfo/odrClueInfoUpdateDetail");
        view.addObject("id", id);
        OdrClueInfoVO odrClueInfoVO = this.odrClueInfoService.selectById(Long.valueOf(id));
        //推荐人信息
        List<Long> refUsrList = new ArrayList<Long>();
        refUsrList.add(odrClueInfoVO.getUsrId());
        List<SysRefUsrDTO> sysRefUsrDTOs = this.sysUsrQueryApiService.searchRefUsrInfoListUp(refUsrList, OdrBscInfoConstant.SYS_CD, SysUsrSysRConstant.REF_USR_BUS_TYP_1);
        List<Long> refUsrOneIds = new ArrayList<>();
        List<Long> refUsrTwoIds = new ArrayList<>();
        List<Long> usrIds = new ArrayList<>();
        for (SysRefUsrDTO sysRefUsrDTO : sysRefUsrDTOs) {
            if (null != sysRefUsrDTO.getRefUsrOneId()) {
                Long refUsrOneId = sysRefUsrDTO.getRefUsrOneId();
                refUsrOneIds.add(refUsrOneId);
            }
            if (null != sysRefUsrDTO.getRefUsrTwoId()) {
                Long refUsrTwoId = sysRefUsrDTO.getRefUsrTwoId();
                refUsrTwoIds.add(refUsrTwoId);
            }
        }
        usrIds.addAll(refUsrOneIds);
        usrIds.addAll(refUsrTwoIds);
        if (CollectionUtils.isNotEmpty(usrIds) || usrIds.size() > 0) {
            List<SysUsrDTO> sysUsrDTOS = sysUsrApiService.selectSysUsrList(usrIds);
            for (SysUsrDTO sysUsrDTO : sysUsrDTOS) {
                Long userId = sysUsrDTO.getId();
                if (refUsrOneIds.contains(userId)) {
                    odrClueInfoVO.setOneMp(sysUsrDTO.getMp());
                }
                if (refUsrTwoIds.contains(userId)) {
                    odrClueInfoVO.setTwoMp(sysUsrDTO.getMp());
                }
            }
        }
        if (StringUtils.isEmpty(odrClueInfoVO.getOneMp()) && StringUtils.isNotEmpty(odrClueInfoVO.getRcdId()) && "BX_01".equals(odrClueInfoVO.getResCd())) {
            SysUsrDTO usrDTO = sysUsrApiService.selectSysUsrById(odrClueInfoVO.getRcdId(), "11000", "0000");
            if (null != usrDTO) {
                odrClueInfoVO.setOneMp(usrDTO.getMp());
            }
        }
        Map<String, String> clueStsMap = this.sysDictionaryApiService.searchGroupToMap(OdrCommonConstant.SYS_CD, OdrCommonConstant.ORG_CD, OdrCommonConstant.CODE_GRP_CD_CLUE);
        odrClueInfoVO.setClueStsCdNm(clueStsMap.get(odrClueInfoVO.getClueStsCd()));

        List<OdrClueRemVO> remList = odrClueRemService.selectRemListByClueId(id);
        BaseLogUtils.info(logger, "selectRemListByClueId", "通过线索id查询备注列表", CurrentThreadContext.getCurrentUserName());
        view.addObject("odrClueInfoVO", odrClueInfoVO);
        view.addObject("remList", remList);
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toDetailPage", " 加载例子详细页面.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        return view;
    }

    /**
     * 修改状态已经保存
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/changeStatus.do", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object changeStatis(HttpServletRequest request, HttpServletResponse response) {
        OdrClueInfoVO vo = new OdrClueInfoVO();
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES);
        String id = request.getParameter("clueId");
        String status = request.getParameter("clueStsCd");
        //ODR_REM 备注
        String odrRem = request.getParameter("odrRem");
        if (StringUtils.isEmpty(odrRem)) {
            BaseLogUtils.info(logger, "changeStatus", "调用请求 changeStatus ：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
        } else {
            vo.setOdrRem(odrRem);
        }
        if (StringUtils.isNotEmpty(id)) {
            BaseLogUtils.info(logger, "changeStatus", "调用请求 changeStatus ：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
            vo.setId(Long.valueOf(id));
            vo.setClueStsCd(status);
            try {
                boolean modify = odrClueInfoService.modify(vo);
                if (Objects.equals(modify, false)) {
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("修改失敗!");
                    BaseLogUtils.info(logger, "changeStatus", "修改失敗", CurrentThreadContext.getCurrentUserName());
                }
                BaseLogUtils.info(logger, "changeStatus", "调用请求 changeStatus成功！ ：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
                return result;
            } catch (Exception e) {
                e.printStackTrace();
                result.setSuccess(0);
                BaseLogUtils.info(logger, "changeStatus", "调用请求 changeStatus失败！ ：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
            }
        }
        return result;
    }


    @ResponseBody
    @RequestMapping("/addRem.do")
    public Object addRem(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //clueId 线索id
        String clueId = request.getParameter("clueId");
        //备注
        String odrRem = request.getParameter("odrRem");
        //当前操作用姓名，id
        String userName = CurrentThreadContext.getCurrentUserName();
        Long userId = CurrentThreadContext.getCurrentUserId();


        DataResultVO result = new DataResultVO();

        OdrClueRemVO odrClueRemVO = new OdrClueRemVO();
        if (StringUtils.isBlank(clueId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("线索ID不能为空.");
            BaseLogUtils.info(logger, "addRem", "添加备注，线索id不存在.[id=" + clueId + "]", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        odrClueRemVO.setClueId(Long.valueOf(clueId));
        odrClueRemVO.setComment(odrRem);

        if (StringUtils.isNotEmpty(userName)) {
            odrClueRemVO.setCrtUsrNm(userName);
        }
        if (StringUtils.isNotEmpty(userId)) {
            odrClueRemVO.setCrtUsrId(userId);
        }
        BaseLogUtils.info(logger, "addRem", "调用请求 addRem ：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        boolean b = odrClueRemService.add(odrClueRemVO);
        if (!b) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("添加失败");
            BaseLogUtils.info(logger, "addRem", "添加备注失败", CurrentThreadContext.getCurrentUserName());
        } else {
            result.setSuccess(BaseConstant.IS_YESNO_YES);
            result.setInfo("添加成功");
            BaseLogUtils.info(logger, "addRem", "添加备注成功", CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }


    /*@RequestMapping(value = "/download.do", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseEntity<byte[]> download(HttpServletRequest request, HttpServletResponse response) throws IOException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "download", "导出excle.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String odrNo = request.getParameter("odrNo");//线索编号
        String cstNm = request.getParameter("cstNm");//客户名称
        String cstMgrNm = request.getParameter("cstMgrNm");//客户经理
        String odrStsCd = request.getParameter("odrStsCd");//线索状态
        String firstUsrNm = request.getParameter("firstUsrNm");//一级推荐人id
        String secondUsrNm = request.getParameter("secondUsrNm");//二级推荐人id
        String buOrgCd = request.getParameter("buOrgCd");//所属事业部
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");

        ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
        SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
        Sheet sheet = sxssfWorkbook.createSheet("线索信息");
        Row titleRow = sheet.createRow(0);
        titleRow.createCell(0).setCellValue("编号");
        titleRow.createCell(1).setCellValue("客户");
        titleRow.createCell(2).setCellValue("联系电话");
        titleRow.createCell(3).setCellValue("一级推荐人");
        titleRow.createCell(4).setCellValue("二级推荐人");
        titleRow.createCell(5).setCellValue("数据来源");
        titleRow.createCell(6).setCellValue("状态");
        titleRow.createCell(7).setCellValue("客户经理");
        titleRow.createCell(8).setCellValue("所属事业部");
        titleRow.createCell(9).setCellValue("创建时间");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        OdrClueInfoQC qc = new OdrClueInfoQC();
        if (StringUtils.isNotEmpty(odrNo)) {
            qc.setClueNo(odrNo);
        }
        if (StringUtils.isNotEmpty(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotEmpty(cstMgrNm)) {
            qc.setCstMgrNm(cstMgrNm);
        }
        if (StringUtils.isNotEmpty(odrStsCd)) {
            qc.setClueStsCd(odrStsCd);
        }
        if (StringUtils.isNotEmpty(firstUsrNm)) {
            qc.setFirstUsrNm(firstUsrNm);
        }
        if (StringUtils.isNotEmpty(secondUsrNm)) {
            qc.setSecondUsrNm(secondUsrNm);
        }

        if (StringUtils.isNotEmpty(buOrgCd)) {
            qc.setBuOrgCd(buOrgCd);
        }
        if (StringUtils.isNotEmpty(beginTime)) {
            qc.setBeginTime(DateUtil.getDateByStringTime(beginTime));
        }
        if (StringUtils.isNotEmpty(endTime)) {
            qc.setEndTime(DateUtil.getDateByStringTime(endTime));
        }

        //数据权限
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        qc.setDataUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
        page.setCondition(qc);
        Pager pager = this.odrClueInfoService.searchListPage(page);
        List<OdrClueInfoVO> list = (List<OdrClueInfoVO>) pager.getResultList();
        List<Long> userIdList = new ArrayList<>();
        int index = 1;
        for (OdrClueInfoVO odrClueInfoVO : list) {
            userIdList.add(odrClueInfoVO.getUsrId());
        }
        List<SysUsrDTO> sysUsrDTOS = sysUsrApiService.selectSysUsrList(userIdList);
        for (OdrClueInfoVO odrClueInfoVO : list) {
            for (SysUsrDTO sysUsrDTO : sysUsrDTOS) {
                if (odrClueInfoVO.getUsrId() == sysUsrDTO.getId()) {
                    odrClueInfoVO.setUsrMp(sysUsrDTO.getMp());
                }
            }
        }
        for (OdrClueInfoVO odrClueInfoVO : list) {

            *//**
     *  titleRow.createCell(0).setCellValue("编号");
     *         titleRow.createCell(1).setCellValue("客户");
     *         titleRow.createCell(2).setCellValue("一级推荐人");
     *         titleRow.createCell(3).setCellValue("二级推荐人");
     *         titleRow.createCell(4).setCellValue("数据来源");
     *         titleRow.createCell(5).setCellValue("状态");
     *         titleRow.createCell(6).setCellValue("客户经理");
     *         titleRow.createCell(7).setCellValue("所属事业部");
     *         titleRow.createCell(8).setCellValue("创建时间");
     *//*
            Row row = sheet.createRow(index);
            row.createCell(0).setCellValue(odrClueInfoVO.getClueNo());
            row.createCell(1).setCellValue(odrClueInfoVO.getCstNm());
            row.createCell(2).setCellValue(odrClueInfoVO.getUsrMp());
            row.createCell(3).setCellValue(odrClueInfoVO.getOneMp());
            row.createCell(4).setCellValue(odrClueInfoVO.getTwoMp());
            row.createCell(5).setCellValue(odrClueInfoVO.getDateResCdNm());
            row.createCell(6).setCellValue(odrClueInfoVO.getClueStsCdNm());
            row.createCell(7).setCellValue(odrClueInfoVO.getCstMgrNm());
            row.createCell(8).setCellValue(odrClueInfoVO.getBuOrgCdNm());
            row.createCell(9).setCellValue(odrClueInfoVO.getCrtTm());
            index++;
        }

        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "download", "导出excle列表页面.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        sxssfWorkbook.write(new BufferedOutputStream(byteArrayBuilder));
        String filename = "clue.xlsx";
        HttpHeaders headers = new HttpHeaders();
        headers.setContentDispositionFormData("attachment", filename);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        headers.setAcceptCharset(Collections.singletonList(Charset.defaultCharset()));
        return new ResponseEntity<>(byteArrayBuilder.toByteArray(), headers, HttpStatus.CREATED);
    }*/

    /**
     * 导出线索记录
     */
    @RequestMapping(value = "/exportOdrClueInfoDetail.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportOdrClueInfoDetail(HttpServletRequest request, HttpServletResponse response) {
        long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "exportOdrClueInfoDetail", "导出线索记录.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        DataResultVO result = new DataResultVO();
        //设置查询条件
        String odrNo = request.getParameter("odrNo");            //线索编号
        String cstNm = request.getParameter("cstNm");            //客户名称
        String beginTime = request.getParameter("beginTime");    //开始时间
        String endTime = request.getParameter("endTime");        //结束时间
        String odrStsCd = request.getParameter("odrStsCd");      //线索状态
        String buOrgCd = request.getParameter("buOrgCd");        //所属事业部

        OdrClueInfoQC qc = new OdrClueInfoQC();
        if (StringUtils.isNotEmpty(odrNo)) {
            qc.setClueNo(odrNo);
        }
        if (StringUtils.isNotEmpty(cstNm)) {
            qc.setCstNm(cstNm);
        }
        
        /*
        if(StringUtils.isEmpty(odrNo) && StringUtils.isEmpty(cstNm) && StringUtils.isEmpty(odrStsCd) && StringUtils.isEmpty(beginTime) && StringUtils.isEmpty(endTime)){
        	//默认查询最近3天的数据
        	Date befYesterDay = DateUtils.getDateAddDate(new Date(), 5, -2);
            qc.setBeginTime(DateUtils.formatDate(befYesterDay, DateUtils.YYYY_MM_DD));
            qc.setEndTime(DateUtils.getCurrentDate(DateUtils.YYYY_MM_DD));
        }*/

        if (StringUtils.isNotEmpty(beginTime)) {
            qc.setBeginTime(DateUtils.formatStringToDate(beginTime, DateUtils.YYYY_MM_DD));
        }
        if (StringUtils.isNotEmpty(endTime)) {
            qc.setEndTime(DateUtils.formatStringToDate(endTime, DateUtils.YYYY_MM_DD));
        }
        if (StringUtils.isNotEmpty(odrStsCd)) {
            qc.setClueStsCd(odrStsCd);
        }
        if (StringUtils.isNotEmpty(buOrgCd)) {
            qc.setBuOrgCd(buOrgCd);
        }

        //数据权限
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());         //当前系统代码
        qc.setDataUsrId(CurrentThreadContext.getCurrentUserId());    //当前用户ID
        try {
            String path = this.odrClueInfoService.exportOdrClueInfoDetail(qc, CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());
            if (StringUtils.isNotEmpty(path)) {
                result.setSuccess(BaseConstant.IS_YESNO_YES);
                result.setInfo(SysLogConstant.LOG_BK_EXPORT_SUCC);
                result.setData(path);
                BaseLogUtils.info(logger, "exportOdrClueInfoDetail", "导出线索记录数成功", CurrentThreadContext.getCurrentUserName());
            }
        } catch (BaseException e) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(e.getMessage());
            BaseLogUtils.error(logger, "exportOdrClueInfoDetail", "导出线索记录数失败.ERROR：" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception e) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "exportOdrClueInfoDetail", "导出线索记录数失败,系统错误..ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
        }

        long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "exportOdrClueInfoDetail", "导出线索记录.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

   /* @RequestMapping("/toEplyInfoList.do")
    public ModelAndView toEplyInfoPage(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toEplyInfoList", "加载H5招聘信息列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
        OdrEplyInfoQC condition =new OdrEplyInfoQC();
        ModelAndView view = new ModelAndView("carloan/odreplyinfo/odreplyinfoList");
        List<OdrEplyInfoDTO> odrEplyInfoList = odrEplyInfoApiService.selectList(condition);
        view.addObject("odrEplyInfoList", odrEplyInfoList);
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toEplyInfoList", "加载H5招聘信息列表页面.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        return view;
    }*/

   /* @RequestMapping(value = "/initEplyInfoList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initEplyInfoList(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initEplyInfoList", "加载H5招聘信息列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String id = request.getParameter("id");
        String eplyNm = request.getParameter("eplyNm");
        String eplyPhe = request.getParameter("eplyPhe");
        String city = request.getParameter("city");
        String eplyPstn = request.getParameter("eplyPstn");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        OdrEplyInfoQC qc = new OdrEplyInfoQC();
        if (StringUtils.isNotEmpty(id)) {
            qc.setId(Long.valueOf(id));
        }
        if (StringUtils.isNotEmpty(eplyNm)) {
            qc.setEplyNm(eplyNm);
        }
        if (StringUtils.isNotEmpty(eplyPhe)) {
            qc.setEplyPhe(eplyPhe);
        }
        if (StringUtils.isNotEmpty(city)) {
            qc.setCity(city);
        }
        if (StringUtils.isNotEmpty(eplyPstn)) {
            qc.setEplyPstn(eplyPstn);
        }
       if (StringUtils.isNotEmpty(beginTime)) {
           Date dateByStringTime = DateUtil.getDateByStringTime(beginTime);
           Date dateAddDate = DateUtils.getDateAddDate(dateByStringTime, 5, -1);
           qc.setBeginTime(dateAddDate);
        }
        if (StringUtils.isNotEmpty(endTime)) {
            Date dateByStringTime = DateUtil.getDateByStringTime(endTime);
            Date dateAddDate = DateUtils.getDateAddDate(dateByStringTime, 5, -1);
            qc.setEndTime(dateAddDate);
        }

        //数据权限
        page.setCondition(qc);

        Pager pager = this.odrEplyInfoApiService.searchListPage(page);
        List<OdrEplyInfoVO> list = (List<OdrEplyInfoVO>) pager.getResultList();

        ListPageVO<OdrEplyInfoVO> listPage = new ListPageVO<OdrEplyInfoVO>(list, pager.getTotalCount());

        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initEplyInfoList", "加载H5招聘列表页面.耗时：" + (endTm - startTm), CurrentThreadContext.getCurrentUserName());
        return listPage;
    }
*/

    /**
     * 更新线索用户征信等级
     * @param request
     * @param response
     * @return
     */
    
    /*
    @RequestMapping(value = "/updateOdrClueCredit.do", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object updateOdrClueCredit(HttpServletRequest request, HttpServletResponse response){
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES);
        String clueId = request.getParameter("clueId");
        if (StringUtils.isEmpty(clueId)) {
        	  result.setSuccess(BaseConstant.IS_YESNO_NO);
              result.setInfo("线索用户ID不允许为空");
              return result;
        }
        
        try {
            Long resultId = this.odrClueInfoService.updateOdrClueCredit(Long.valueOf(clueId));
            if (resultId != null) {
                result.setSuccess(BaseConstant.IS_YESNO_YES);
                result.setInfo("更新成功,稍后刷新");
                BaseLogUtils.info(logger, "updateOdrClueCredit", "车抵贷更新用户征信成功", CurrentThreadContext.getCurrentUserName());
            }
        } catch (BaseException e) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(e.getMessage());
            BaseLogUtils.error(logger, "updateOdrClueCredit", "车抵贷更新用户征信失败.ERROR：" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception e) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "updateOdrClueCredit", "车抵贷更新用户征信失败,系统错误..ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
    	
    	return result;
    }
    */
    
    /*
    @RequestMapping(value = "/searchWhetherHasCreditTest.do", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object searchWhetherHasCredit(){
    	boolean ret = this.odrClueInfoService.searchWhetherHasCreditTest();
    	DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES);
    	result.setData(ret);
    	return result;
    }
    */


}

